﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using RestaurantManager.DataAcess;
using RestaurantManager.BusinessObject;
namespace RestaurantManager.BusinessLogic
{
   class UserBUS
    {
        private ConnectData connData = new ConnectData();
        public User LayThongTinUser(string userName)
        {
            string sql = "select [User], MatKhau, HoTen, MaNhom, TenNhom"
                        + " From NguoiDung a, NhomNguoiDung b where a.MaNhom = b.ID"
                        + " and [User] = '" + userName + "'";
            DataTable tbUser = connData.ExecuteDataTable(sql);
            User user = new User();
            if (tbUser.Rows.Count > 0)
            {
                DataRow rowUser = tbUser.Rows[0];
                user.user = rowUser["User"].ToString();
                user.pass = rowUser["MatKhau"].ToString();
                user.HoTen = rowUser["HoTen"].ToString();
                user.MaNhom = Convert.ToInt32(rowUser["MaNhom"].ToString());
                user.TenNhom = rowUser["TenNhom"].ToString();
            }
            else
            {
                user.user = "";
                user.pass = "";
                user.HoTen = "";
                user.MaNhom = 0;
                user.TenNhom = "";
            }

            return user;

        }
        public bool SuaMatKhau(string pass)
        {
            pass = Utilities.MahoaMD5(pass);
            string sql = "Update NguoiDung set MatKhau = '"+pass+"' where [User] = '"+Utilities.user.user+"'";
            if (connData.ExecuteQuery(sql))
                return true;
            return false;
        }
    }
}
